#define ARDUINO
#include <EEPROM.h>


#include <que.h>
#include <command.h>
#include "serialProcessor.h"
#include "peltierControl.h"

//#define DEBUG

Que Q;
Command C;

// HW 
#define led1 13
#define led2 12
#define led3 11

uint8_t led1State;
uint8_t led2State;
uint8_t led3State;



// SW
#define absisAdd 0
#define ordinAdd 1
#define KpAdd 2
#define KiAdd 3
#define KdAdd 4

uint8_t pAbsis, pOrdinat;
uint8_t targetTemp;
uint8_t actTemp;
uint8_t bgTemp;
uint8_t Kp, Ki, Kd;

void setup(){
	Serial.begin(115200); 
	
	pinMode(led1, OUTPUT);
	//pinMode(led2, OUTPUT);
	//pinMode(led3, OUTPUT);	
	
	led1State = 1;
	//led2State = HIGH;
	//led3State = HIGH;
	
	//digitalWrite(led2, led2State);
	//digitalWrite(led3, led3State);
	
	makeEmpty(&Q);
	
	pAbsis = EEPROM.read(absisAdd);
	pOrdinat = EEPROM.read(ordinAdd);
	
	Kp = EEPROM.read(KpAdd);
	Ki = EEPROM.read(KiAdd);
	Kd = EEPROM.read(KdAdd);
	

}

void loop(){ 
	while (Serial.available() > 0) {
		// Menerima Command dari rs 485 bus
		// Menggunakan pAbsis, pOrdinat
		// (Mungkin) Mengupdate pAbsis, pOrdinat, targetTemp, Kp, Ki, Kd
		// (Mungkin) Mengirim actTemp, bgTemp
		serialProc();
	}
	
	// Mengontrol Thermoelektrik dengan kontrol PD
	// Mengupdate actTemp, bgTemp
	// Menggunakan pAbsis, pOrdinat, targetTemp, Kp, Ki, Kd 
	peltierControl();
}


